#include <rtime.hpp>

uint64_t rt_current(void)
{
	struct timeval timers = { 0 };
	if (gettimeofday(&timers, NULL) < 0)
	{
		return 0;
	}
	uint64_t now = timers.tv_sec * 1000000 + timers.tv_usec;
	return now;
}

int rt_string(char* o_str, int size)
{
	time_t tt			  = time(NULL);
	struct tm* stm		  = localtime(&tt);
	struct timeval timers = { 0 };
	gettimeofday(&timers, NULL);
	return snprintf(o_str, size, "%04d-%02d-%02d_%02d-%02d-%02d.%03ld", 1900 + stm->tm_year, 1 + stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec, timers.tv_usec / 1000);
}
